package com.sweet.logging.appender;

import com.sweet.logging.logger.LoggingEvent;

import java.time.*;
import java.time.format.DateTimeFormatter;

/**
 *
 * 本地控制台输出日志
 *
 * @author xiexiaofeng
 * @version 1.0     2017年09月08日  11点53分
 */
public class StdoutAppender implements Appender
{
    public static final String CONFIG_NAME = "stdout";

    /**
     * 输出到控制台
     * @param event 写日志事件
     */
    @Override
    public void write(LoggingEvent event)
    {
        Instant instant = Instant.ofEpochMilli(event.getTimeStamp());
        LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        String dataTimeStr = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println(dataTimeStr + " " + event.getLevel() + " [" + event.getName() + "] " + event.getMessage());
    }
}
